package com.zzy.redis.test;

import org.apache.commons.pool2.impl.GenericObjectPoolConfig;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

import java.util.Iterator;
import java.util.Set;

public class RedisKeyJava {
    public static void main(String[] args) {
        //连接本地的 Redis 服务


        //连接本地的 Redis 服务
        String url = "192.168.125.130";//localhost
        //Jedis jedis = new Jedis(url,6379);// http://192.168.125.130/
        GenericObjectPoolConfig poolConfig = new GenericObjectPoolConfig();
        JedisPool jedisPool = new JedisPool(poolConfig,url, 6379, 100000,"zzy");//给redis设置了密码zzy
        Jedis jedis = jedisPool.getResource();


        System.out.println("连接成功");
 
        // 获取数据并输出
        Set<String> keys = jedis.keys("*"); 
        Iterator<String> it=keys.iterator() ;   
        while(it.hasNext()){   
            String key = it.next();   
            System.out.println(key);   
        }
    }
}
